package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.utils.CodeUtil;
import com.lw.sbdemo2.common.utils.ValidUtil;
import com.lw.sbdemo2.entity.TkUserInfo;
import com.lw.sbdemo2.mapper.TkUserInfoMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>标题: 简单服务 - 请求控制层</p>
 * <p>描述: 基础操作</p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2018-6-10
 */
@Api(description = "SimpleController", tags = {"简单测试接口"})
@RestController
public class SimpleController extends BaseController {

    @Autowired
    private TkUserInfoMapper tkUserInfoMapper;

    @ApiOperation(value = "拼音码生成")
    @RequestMapping("/spellCode")
    public void spellCode() throws Exception {
        List<TkUserInfo> zyStaffInfos = tkUserInfoMapper.findList(new TkUserInfo());
        for (TkUserInfo zyStaffInfo : zyStaffInfos) {
            String temp = zyStaffInfo.getUserName();
            if (ValidUtil.isEmptyOrNull(temp)) {
                temp = zyStaffInfo.getNickName();
            }
            if(ValidUtil.isNotEmptyAndNull(temp)){
                String tmp2 = CodeUtil.cn2FirstSpell(temp);
                if(tmp2 != null && tmp2.length() > 0){
                    System.out.println(tmp2);
                    tkUserInfoMapper.updateSpell(zyStaffInfo.getUserId(), tmp2.substring(0, 1));
                }
            }
        }
    }
}
